using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace PaperFighter
{
    class GameOver : GameScreen
    {
        Texture2D background, gameover;
        float transparence = 0.0f;
        bool isExit = false;

        public override void LoadContent()
        {
            background = ScreenManager.Game.Content.Load<Texture2D>("background_1");
            gameover = ScreenManager.Game.Content.Load<Texture2D>("gameover");

            base.LoadContent();
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (!isExit)
            {
                if (transparence < 1)
                    transparence += 0.1f;
            }
            else
            {
                if (transparence < 0)
                {
                    ExitScreen();
                    ScreenManager.AddScreen(new Select(), null);
                }
                
                transparence -= 0.05f;
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void HandleInput(InputState input)
        {
            if (input == null)
               throw new ArgumentNullException("input");

            PlayerIndex playerIndex;
            if (input.IsMenuCancel(null, out playerIndex))
            {
                isExit = true;
            }

            if (input.TouchState.Count > 0)
            {
                int touchPositionY = (int)input.TouchState[0].Position.Y;
                if (touchPositionY >= 590 && touchPositionY <= 680)
                    isExit = true;
            }
            
            base.HandleInput(input);
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.Draw(background, Vector2.Zero, Color.White);
            ScreenManager.SpriteBatch.Draw(gameover, Vector2.Zero, Color.White * transparence);
            ScreenManager.SpriteBatch.End();
            
            base.Draw(gameTime);
        }
    }
}
